import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Req,
  Query,
  Put,
} from '@nestjs/common';
import { WorksService } from './works.service';
import { CreateWorkDto, UpdateWorkDto } from './dto/create-work.dto';
import {
  ApiBearerAuth,
  ApiOperation,
  ApiQuery,
  ApiTags,
} from '@nestjs/swagger';
import { Roles, RolesGuard } from 'src/auth/role.guard';
import { AuthGuard } from '@nestjs/passport';

@ApiTags('作品')
@Controller('works')
export class WorksController {
  constructor(private readonly WorksService: WorksService) {}

  @ApiBearerAuth()
  @Post()
  @Roles('admim', 'root')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async create(@Body() createWorkDto: CreateWorkDto) {
    return this.WorksService.create(createWorkDto);
  }

  @Get('/list')
  @ApiQuery({ name: 'status', required: false, type: String })
  async findAll(
    @Query() query,
    @Query('pageSize') pageSize: number,
    @Query('pageNum') pageNum: number,
    @Query('status') status?: string,
  ) {
    return this.WorksService.findAll(query);
  }

  @ApiOperation({ summary: '获取指定项目' })
  @Get('/getById')
  findOne(@Query('id') id: string) {
    return this.WorksService.findOne(+id);
  }

  @ApiOperation({ summary: '更新指定项目' })
  @ApiBearerAuth()
  @Put('/update')
  @Roles('admim', 'root')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  update(@Body() works: UpdateWorkDto) {
    return this.WorksService.update(works);
  }

  @ApiBearerAuth()
  @Delete('/delete')
  @Roles('admim', 'root')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async remove(@Query('id') id: number) {
    return await this.WorksService.remove(+id);
  }
}
